var path = require('path')
var webpack = require('webpack')

module.exports = {
  entry: './src/main.js',
  output: {
    path: path.resolve(__dirname, './dist'),
    publicPath: '/dist/',
    filename: 'build.js'
  },
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          loaders: {
          }
          // other vue-loader options go here
        }
      },
      {
				test:/\.css$/,
				loader:'style-loader!css-loader!autoprefixer-loader' //加载顺序先执行css-loader再执行style-loader所以这个编写的顺序一定不能颠倒，否则无效
			},
      {
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: /node_modules/
      },
      {
        test: /\.(eot|woff|svg|ttf|woff2|gif)$/,
        loader: 'file-loader',
        options: {
          name: '[name].[ext]?[hash]'
        }
      },
       {
		    test: /\.(png|jpg)$/,  //表示匹配的文件后缀名为 .png 或者.jpg也可以自己增加
		    loader: 'url-loader?limit=40000' // url其实就是url-loader的缩写,后面的limit表示如果图片大小小于40000，那么则将这张图片编译成base64的字符串给浏览器使用，否则将图片打包到编译文件夹中（图片大小不不变），这里注意一下，值不能太大，否则会导致build.js文件过大影响性能
		   }
    ]
  },
  resolve: {
    alias: {
      'vue$': 'vue/dist/vue.esm.js'
    }
  },
  devServer: {
    historyApiFallback: true,
    noInfo: true
  },
  performance: {
    hints: false
  },
  devtool: '#eval-source-map'
}

if (process.env.NODE_ENV === 'production') {
  module.exports.devtool = '#source-map'
  // http://vue-loader.vuejs.org/en/workflow/production.html
  module.exports.plugins = (module.exports.plugins || []).concat([
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: '"production"'
      }
    }),
    new webpack.optimize.UglifyJsPlugin({
      sourceMap: true,
      compress: {
        warnings: false
      }
    }),
    new webpack.LoaderOptionsPlugin({
      minimize: true
    })
  ])
}
